<?
	include_once "../classes/init.php";
	
	for( $i = 1; $i < 100; $i++ ) {
		$page = "";
		$page = fopen("http://www.maneige.com/fr/infos_pratiques/infostations.php?id=" . $i . "#contenu", "rb");
		if( !empty( $page ) ) {
			$contenu = stream_get_contents( $page );
			$nom = "";
			$cp = "";
			$adresse = "";
			$province = "";
			$tel = "";
			$tabArg = array();
			@$doc = DOMDocument::loadHTML( $contenu );
			$objXpath = new domxpath( $doc );
			$requeteNomMontagne = "/html/body/center/div[@id='container']/table[@id='tbl_3colonnes']/tr/td[@id='td_2e_col_infos']/div[@id='sstfiche_default_first']";
			$objNodeList1 = $objXpath->query( $requeteNomMontagne );
			foreach ( $objNodeList1 as $node ){
				$nom = str_replace( "\t", "", $node->nodeValue );
				echo $nom;
			}
			$requeteInfosMontagnes = "/html/body/center/div[@id='container']/table[@id='tbl_3colonnes']/tr/td[@id='td_2e_col_infos']/div[@class='padding_margin']/table/tr/td/p";
			$objNodeList2 = $objXpath->query( $requeteInfosMontagnes );
			foreach ( $objNodeList2 as $node ){
				$infos = str_replace( "\t", "", $node->nodeValue );
				$tab = split( "\n", $infos );
				$adresse = $tab[ 0 ];
				$province = str_replace( "(" , "", str_replace( ")", "", $tab[ 1 ] ) );
				$ville = $tab[ 2 ];
				$cp = $tab[ 3 ];
				$tel = $tab[ 4 ];
			}
			
			$requeteInfosUrl = "/html/body/center/div[@id='container']/table[@id='tbl_3colonnes']/tr/td[@id='td_2e_col_infos']/div[@class='padding_margin']/table/tr/td/a";
			$objNodeList3 = $objXpath->query( $requeteInfosUrl );
			foreach ( $objNodeList3 as $node ){
				//echo $node->nodeValue;
				$att = $node->attributes;
				foreach( $att as $arg ) {
					$tabArg[] = $arg->nodeValue;
				}
			}
			$url = $tabArg[ 1 ];
			/* ajout dans la base de données */
			if( !empty( $nom ) && !empty( $url ) && !empty( $ville ) && !empty( $cp ) && !empty( $adresse ) && !empty( $tel ) && !empty( $province ) ) {
				$req = "INSERT INTO montagnes( nom, latitude, longitude, url, ville, codePostal, adresse, tel, province )
									VALUES( '" . addslashes( $nom ) . "', 0, 0, '$url', '" . addslashes( $ville ) . "', '$cp', '" . addslashes( $adresse ) . "', '$tel', '$province'  )";
				$objBD->query( $req );
			}
		}
	}


?>